package com.deyili.lease.web.admin.controller.apartment;


import com.deyili.lease.common.result.Result;
import com.deyili.lease.model.entity.PaymentType;
import com.deyili.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {
    @Autowired
    PaymentTypeService paymentTypeService;
    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result<List<PaymentType>> listPaymentType() {
        List<PaymentType> list = paymentTypeService.list();
        return Result.ok(list);
    }

    @Operation(summary = "保存或更新支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdatePaymentType(@RequestBody PaymentType paymentType) {
//        在这里面写智能这里面用，其他地方还有这种，需要考虑面向切面编程(在baseEntity中使用注解进行标记，新建一个类MybatisMetaObjectHandler监听mybatis数据库行为)
//        第一中情况：添加
//        if (paymentType.getId()==null){
//            //        创建时间
//            paymentType.setCreateTime(new Date());
//        }else {
//            paymentType.setUpdateTime(new Date());
//        }

        paymentTypeService.saveOrUpdate(paymentType);
        return Result.ok();
    }

    @Operation(summary = "根据ID删除支付方式")
    @DeleteMapping("deleteById")
    public Result deletePaymentById(@RequestParam Long id) {
        paymentTypeService.removeById(id);
        return Result.ok();
    }

}















